package com.example.logindb.repository;

import com.example.logindb.entity.Help;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.sql.Timestamp;
import java.util.List;

@Repository
public interface HelpRepository extends JpaRepository<Help, Integer> {
    List<Help> findAllByBid(int id);

    @Query(
            "SELECT h FROM Help h WHERE h.status = 0 AND h.lat BETWEEN :minLat AND :maxLat AND h.lon BETWEEN :minLon AND :maxLon"
    )
    List<Help> findBlindMessage(
            Double minLat,
            Double maxLat,
            Double minLon,
            Double maxLon
    );


    Help findAllByAid(Integer aid);

    List<Help> findAllByVid(Integer vid);

    @Query(
            value = "SELECT h FROM Help h WHERE  h.stime >= :startTime AND h.status=2"//帮助完成
    )
    List<Help> findRecentMessagesWithVidMinusOne(Timestamp startTime);

    @Query(
            value = "SELECT h FROM Help h WHERE  h.stime >= :startTime AND h.status=3"//帮助超时
    )
    List<Help> findRecentMessagesOvertime(Timestamp startTime);

    @Query("SELECT h FROM Help h WHERE h.status = 2 AND h.bid = :bid")
    List<Help> findAllByBidDone(Integer bid);

    @Query("SELECT h FROM Help h WHERE h.status = 2 AND h.vid = :vid")
    List<Help> findAllByVidDone(Integer vid);

    @Query("SELECT h FROM Help h WHERE h.status = 1 AND h.vid = :vid")
    Help findAllByVidAndStatus(int vid);

    List<Help> findAllByStatus(int i);
}
